<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../day3/css/style.css">
</head>

<body>

    <div class="catbox">
        <table id="cartTable">
            <thead>
                <tr>
                    <th>
                        <label for="">
                            <input type="checkbox">&nbsp;&nbsp;全选
                        </label>
                    <th>商品</th>
                    <th>单价</th>
                    <th>数量</th>
                    <th>小计</th>
                    <th>操作</th>
                    </th>
                </tr>
            </thead>
            <tbody>

            </tbody>

        </table>
        <div class="foot" id="foot">

            <a class="fl" id="deleteAll" href="javascript:;">删除</a>
            <div class="fr closing" onclick="getTotal();">结 算</div>
            <input type="hidden" id="cartTotalPrice" />
            <div class="fr total">合计：￥<span id="priceTotal">0.00</span></div>
            <div class="fr selected" id="selected">已选商品<span id="selectedTotal">0</span>件<span
                    class="arrow up">︽</span><span class="arrow down">︾</span></div>
            <div class="selected-view">
                <div id="selectedViewList" class="clearfix">
                    <div><img src="../day3/images/1.jpg"><span>取消选择</span></div>
                </div>
                <span class="arrow">◆<span>◆</span></span>
            </div>
        </div>
    </div>

    <script>
        var tbody = document.querySelector("#cartTable tbody");
        var xhr = new XMLHttpRequest();
        xhr.open("get", "../day3/data/data.json", true)
        xhr.send()
        xhr.onreadystatechange = function () {
            // console.log(1)
            if (xhr.readyState == 4 && xhr.status == 200) {
                var data = JSON.parse(xhr.responseText)
                console.log(data)
                var html = ``
                data.forEach(({ goodsName, goodsPrice, goodsImg, buyNum }) => html += `
                <tr>
                    <td class="checkbox"><input class="check-one check" type="checkbox" /></td>
                    <td class="goods"><img src="${goodsImg}" alt="" /><span>${goodsName}</span></td>
                    <td class="price">${goodsPrice.toFixed(2)}</td>
                    <td class="count"><span class="reduce"></span>
                        <input class="count-input" type="text" value="${buyNum}" />
                        <span class="add">+</span>
                    </td>
                    <td class="subtotal">${(buyNum * goodsPrice).toFixed(2)}</td>
                    <td class="operation"><span class="delete">删除</span></td>
                </tr>
                `)
                tbody.innerHTML = html
            }
        }
    </script>
</body>

</html>